Skip to content

Conversation

@cesaralexanderds
Copy link

@cesaralexanderds cesaralexanderds commented Jan 10, 2026

Summary
Fixes the OpenCode extension hanging indefinitely on "Loading..." when opening Git repositories in Zed editor on Windows.

Problem
When opening a Git repository in Zed on Windows, three git commands in Project.fromDirectory() would hang indefinitely:

  • git rev-list --max-parents=0 --all (project ID generation)
  • git rev-parse --show-toplevel (repository root detection)
  • git rev-parse --git-common-dir (worktree detection)
    This caused the Zed extension to freeze during initialization, preventing users from using the OpenCode assistant in any Git repository.

Root Cause
The issue was initially reported as a Zed bug in zed-industries/zed#43335, but investigation revealed it was an OpenCode bug. The git commands were executed without any timeout mechanism, causing indefinite hangs on Windows when called through the Zed Agent Communication Protocol.

Solution
Added a gitWithTimeout() helper function that wraps git command promises with a 5-second timeout using Promise.race(). When a timeout occurs:

  • Logs a warning message for debugging (log.warn)
  • Returns the fallback value (undefined)
  • Triggers existing fallback logic (already in place for when git commands fail)
  • Gracefully degrades to non-git behavior instead of hanging
    The timeout is conservative enough (5 seconds) that it won't affect normal git operations on any platform, but prevents indefinite hangs.

Testing

  • Tested on Windows 11 with Zed 0.218.6
  • Confirmed extension now loads successfully in Git repositories
  • Binary built and tested locally with the patched code
  • No impact on non-Windows platforms (timeout is generous for normal operations)
  • Fallback behavior works correctly when timeout is triggered

Related Issues

Changes

  • Added gitWithTimeout() helper function in packages/opencode/src/project/project.ts
  • Wrapped three git commands with timeout protection
  • Added warning log when timeout occurs for debugging purposes

Fixes #7587

…dows

When opening Git repositories in the Zed editor on Windows, the OpenCode
extension would hang indefinitely on "Loading..." due to git commands
blocking without timeout in Project.fromDirectory().

This adds a gitWithTimeout() helper that wraps git commands with a 5-second
timeout, allowing graceful fallback to non-git behavior instead of hanging.

The three affected git commands are:
- git rev-list --max-parents=0 --all (project ID generation)
- git rev-parse --show-toplevel (repository root detection)
- git rev-parse --git-common-dir (worktree detection)

Tested on Windows with Zed 0.218.6 and confirms the extension now loads
successfully in Git repositories.
@github-actions
Copy link
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions
Copy link
Contributor

The following comment was made by an LLM, it may be inaccurate:

No duplicate PRs found

@jayeshm33-bit
Copy link

Built this locally on Windows 11 and it fixes the hang in existing Zed projects. The git commands were blocking indefinitely before - now they timeout gracefully and Zed proceeds normally. Thanks for the fix.

@cesaralexanderds
Copy link
Author

Built this locally on Windows 11 and it fixes the hang in existing Zed projects. The git commands were blocking indefinitely before - now they timeout gracefully and Zed proceeds normally. Thanks for the fix.

Happy to help !

@rekram1-node
Copy link
Collaborator

Any idea why it hangs infinitely? Ideally we fix that because I think doing this will lead to unexpected outcomes otherwise...

@cesaralexanderds
Copy link
Author

Any idea why it hangs infinitely? Ideally we fix that because I think doing this will lead to unexpected outcomes otherwise...

I've found this as the most promising aswer for this question:

  1. No Built-in Timeout Mechanism
    Bun Shell (which OpenCode uses via the $ template literal) has no built-in timeout for command execution:
  • The BunShellPromise interface has no timeout parameter
  • Commands can run forever without any automatic termination
  • The OpenCode SDK even explicitly disables timeouts: req.timeout = false
  1. Broken stdin State Management (The Core Bug)
    This is might be the root technical cause. Bun Shell has a known bug in how it handles stdin in non-TTY environments:
    From Bun issue #10080:

Bun's FileReader makes incorrect assumptions about file descriptor blocking states. It sets the reader as non-blocking when the file descriptor is actually blocking. The PosixBufferedReader expects non-blocking behavior but gets blocking syscalls, so EAGAIN is never raised.
What this means:

  • stdin is in a blocking state (waiting for data)
  • But Bun treats it as non-blocking
  • The code expects EAGAIN error (meaning "no data available, try again later")
  • EAGAIN never fires because the syscall is actually blocking
  • Result: infinite wait
  1. Git Waits for stdin Input
    Git commands like rev-list, rev-parse can trigger:
  • Credential helpers (asking for passwords)
  • SSH key passphrases
  • GPG signing passphrases
  • Terminal capability detection
    In a normal scenario:
  • If stdin is closed → Git gets EOF → continues or fails gracefully
  • If stdin is unavailable → Git gets error → fails with error message
    But in this broken state:
  • stdin appears open (no EOF signal)
  • stdin provides no data (blocking)
  • stdin throws no error (no EAGAIN due to the bug)
  • Git waits forever thinking input might eventually arrive
  1. Windows Amplifies the Problem
    On Windows specifically:
  • Pipe semantics are different (named pipes vs Unix pipes)
  • Git for Windows uses MSYS2/Cygwin compatibility layer
  • Zed's ACP on Windows may not properly configure pipe modes
  • The combination creates a scenario where stdin is:
    • Open but not readable
    • Not closed
    • Not erroring
    • Just... existing in limbo

The failure process:

  1. Zed spawns OpenCode via ACP (no TTY, stdio pipes)
  2. OpenCode uses Bun Shell to run: git rev-parse --show-toplevel
  3. Bun Shell spawns git process with stdin pipe
  4. Git checks for interactive input / credentials
  5. Git tries to read from stdin
  6. Bun's FileReader has stdin in BLOCKING mode
  7. But Bun treats it as NON-BLOCKING
  8. The read() syscall BLOCKS (waiting for data)
  9. No EAGAIN error is raised (because it's actually blocking)
  10. Git waits indefinitely for data that will never come
  11. No timeout mechanism exists to stop it

    Hang infinitely

@rekram1-node

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Zed extension hangs on "Loading..." when opening Git repositories on Windows

3 participants